package cn.fl.infside.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.infside.service.IInfBfsPayService;
import cn.fl.infside.transform.InfBfsPayVOTransform;
import cn.fl.infside.vo.InfBfsPayVO;
import cn.fl.system.constant.SysLogConstant;
import cn.lb.framework.poi.excel.ExcelExportUtil;
import cn.lb.framework.poi.excel.entity.ExportParams;
import cn.lb.framework.poi.excel.entity.enmus.ExcelType;
import cn.lb.framework.poi.excel.export.styler.ExcelExportStylerDefaultImpl;
import fl.inf.facade.condition.InfBfsPayQueryCondition;
import fl.inf.facade.constant.InterfaceConstants;
import fl.inf.facade.dto.InfBfsPayDTO;
import fl.inf.facade.dto.MessageDTO;

/**
 * @Description: 资金系统支付接口表 控制层
 */
@Controller
@RequestMapping("/infside/infBfsPay")
public class InfBfsPayController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(InfBfsPayController.class);

	/**
	 * InfBfsPay 服务层BEAN
	 */
	@Autowired
	private IInfBfsPayService infBfsPayService;

	/**
	 * 到资金管理首页
	 */
	@RequestMapping(value = "/toInfBfsPayManagePage.do", method = { RequestMethod.GET})
	public ModelAndView toInfWarrantPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("infside/infBfsPay/infBfsPayManagePage");
		BaseLogUtils.info(logger, "toInfBfsPayManagePage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toInfBfsPayList.do", method = { RequestMethod.GET})
	public ModelAndView toInfBfsList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("infside/infBfsPay/infBfsPayList");
		List<Map<String,String>> statuslist = new ArrayList<Map<String,String>>();
		for(InterfaceConstants.BfsPayStatus status : InterfaceConstants.BfsPayStatus.values()){
			Map<String,String> statusmap = new HashMap<String,String>();
			statusmap.put("key",status.key());
			statusmap.put("value",status.desc());
			statuslist.add(statusmap);
		}
		view.addObject("statuslist", statuslist);
		BaseLogUtils.info(logger, "toInfBfsPayList", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("infside/infBfsPay/modify");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initInfBfsPayList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initInfBfsPayList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String status = request.getParameter("status");//状态
		String procInstCode = request.getParameter("procInstCode");//流程编号
		String paylistCode = request.getParameter("paylistCode");//支付表编号
		String customerName = request.getParameter("customerName");//承租人
		String projectName = request.getParameter("projectName");//项目名称
		String provincialCompany = request.getParameter("provincialCompany");//省公司
		String beginCreateTime = request.getParameter("beginCreateTime");//创建时间(起)
		String endCreateTime = request.getParameter("endCreateTime");//创建时间(止)
		String beginPayTime = request.getParameter("beginPayTime");//付款时间(起)
		String endPayTime = request.getParameter("endPayTime");//付款时间(止)
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		InfBfsPayQueryCondition qc = new InfBfsPayQueryCondition();
		if (StringUtils.isNotEmpty(status)) {
			qc.setStatus(status);
		}
		if (StringUtils.isNotEmpty(procInstCode)) {
			qc.setProcInstCode(procInstCode);
		}
		if (StringUtils.isNotEmpty(paylistCode)) {
			qc.setPaylistCode(paylistCode);
		}
		if (StringUtils.isNotEmpty(customerName)) {
			qc.setCustomerName(customerName);
		}
		if (StringUtils.isNotEmpty(projectName)) {
			qc.setProjectName(projectName);
		}
		if (StringUtils.isNotEmpty(provincialCompany)) {
			qc.setProvincialCompany(provincialCompany);
		}
		if (StringUtils.isNotEmpty(beginCreateTime)) {
			qc.setBeginCreateTime(DateUtils.formatStringToDate(beginCreateTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(endCreateTime)) {
			qc.setEndCreateTime(DateUtils.formatStringToDate(endCreateTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(beginPayTime)) {
			qc.setBeginPayTime(DateUtils.formatStringToDate(beginPayTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(endPayTime)) {
			qc.setEndPayTime(DateUtils.formatStringToDate(endPayTime, "yyyy-MM-dd"));
		}
		page.setCondition(qc);

		//TODO SOMETHING
		Pager pager = this.infBfsPayService.searchListPage(page);
		List<InfBfsPayVO> list = InfBfsPayVOTransform.toVOList((List<InfBfsPayDTO>) pager.getResultList());
		for(InfBfsPayVO _vo : list){
			if(StringUtils.isNotEmpty(_vo.getStatus())){
				for(InterfaceConstants.BfsPayStatus _enumstatus : InterfaceConstants.BfsPayStatus.values()){
					if(StringUtils.isNotEmpty(_enumstatus.key()) && (_vo.getStatus()).equals(_enumstatus.key())){
						_vo.setStatusNm(_enumstatus.desc());
						break;
					}
				}
			}
			if(StringUtils.isNotBlank(_vo.getPrjNm())){
				_vo.setProjectName(_vo.getPrjNm());
			}
			if(StringUtils.isNotBlank(_vo.getCstNm())){
				_vo.setCustomerName(_vo.getCstNm());
			}
			if(StringUtils.isNotBlank(_vo.getBuOrgNm())){
				_vo.setOrgNo(_vo.getBuOrgNm());
			}else{
				if(StringUtils.isNotEmpty(_vo.getOrgNo())){
					_vo.setOrgNo(this.infBfsPayService.searchOrgNm(_vo.getOrgNo(), CurrentThreadContext.getCurrentSysCd()));
				}
			}
			if(StringUtils.isNotBlank(_vo.getCstMgrOrgNm())){
				_vo.setProvincialCompany(_vo.getCstMgrOrgNm());
			}else{
				if(StringUtils.isNotEmpty(_vo.getProvincialCompany())){
					_vo.setProvincialCompany(this.infBfsPayService.searchOrgNm(_vo.getProvincialCompany(), CurrentThreadContext.getCurrentSysCd()));
				}
			}
			if(null != _vo.getPayMoneyReal()){
				_vo.setPayMoneyRealdou(DecimalUtils.convertFenToYuan(_vo.getPayMoneyReal()));
			}
			if(null != _vo.getPayMoney()){
				_vo.setPayMoneydou(DecimalUtils.convertFenToYuan(_vo.getPayMoney()));
			}
		}
		ListPageVO<InfBfsPayVO> listPage = new ListPageVO<InfBfsPayVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initInfBfsPayList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.infBfsPayService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			InfBfsPayVO vo = this.infBfsPayService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			vo.setPayMoneyRealdou(DecimalUtils.convertFenToYuan(vo.getPayMoneyReal()));
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		InfBfsPayVO entity = null;
		try {
			entity = new InfBfsPayVO();
			//TODO ADD PARAM
			Long id = this.infBfsPayService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String payerAcc = request.getParameter("payerAcc");
		String payMoneyRealdou = request.getParameter("payMoneyRealdou");
		String payDate = request.getParameter("payDate");
//		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		InfBfsPayVO entity = null;
		try {
			entity = new InfBfsPayVO();
			entity.setId(Long.valueOf(id));
			entity.setPayerAcc(payerAcc); //设置付款人账号
			if (StringUtils.isNotEmpty(payMoneyRealdou)) {
                entity.setPayMoneyReal(DecimalUtils.convertYuanToFen(Double.valueOf(payMoneyRealdou)));
            }
			entity.setPayDate(DateUtils.formatStringToDate(payDate,DateUtils.YYYY_MM_DDHHMM));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.infBfsPayService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 *组织机构信息
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/searchOrgTree.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object searchOrgTree(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功");
		try {

			JSONArray array = new JSONArray();
			array = this.infBfsPayService.searchOrgTreeByCurrentUser(CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getFlServiceSysCd());
			if(null == array){
				array = new JSONArray();
			}

			result.setData(array);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取数据失败！");
			logger.error("获取数据失败！", ex);
		}
		return result;
	}

	/**
	 * 向资金系统发送
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/manualSendPay.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object manualSendPay(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ibfspayId = request.getParameter("ibfspayId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "发送完成");
		if(StringUtils.isEmpty(ibfspayId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "changePayStatus", "参数空.", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			MessageDTO<String> messagedto = this.infBfsPayService.manualSendPay(Long.valueOf(ibfspayId));
			if (!messagedto.isSuccess()) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				//result.setInfo(messagedto.getMessage());
				result.setInfo("发送失败");
				BaseLogUtils.info(logger, "changePayStatus", "发送失败", CurrentThreadContext.getCurrentUserName());
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("发送失败！");
			logger.error("发送失败！", ex);
		}
		return result;
	}

	/**
	 * 向资金系统发送
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/payFailure.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object payFailure(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ibfspayId = request.getParameter("ibfspayId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作完成");
		if(StringUtils.isEmpty(ibfspayId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "changePayStatus", "参数空.", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			MessageDTO<String> messagedto = this.infBfsPayService.payFailure(Long.valueOf(ibfspayId));
			if (!messagedto.isSuccess()) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				//result.setInfo(messagedto.getMessage());
				result.setInfo("发送失败");
				BaseLogUtils.info(logger, "changePayStatus", "发送失败", CurrentThreadContext.getCurrentUserName());
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("发送失败！");
			logger.error("发送失败！", ex);
		}
		return result;
	}
	
	@RequestMapping(value = "/exportInfBfsPayExcel.do", method = {RequestMethod.POST, RequestMethod.GET})
	public void exportInfBfsPayExcel(HttpServletRequest request, HttpServletResponse response) {
		String status = request.getParameter("status");//状态
		String procInstId = request.getParameter("procInstId");//流程编号
		String paylistCode = request.getParameter("paylistCode");//支付表编号
		String customerName = request.getParameter("customerName");//承租人
		String projectName = request.getParameter("projectName");//项目名称
		String provincialCompany = request.getParameter("provincialCompany");//省公司
		String beginCreateTime = request.getParameter("beginCreateTime");//创建时间(起)
		String endCreateTime = request.getParameter("endCreateTime");//创建时间(止)
		String beginPayTime = request.getParameter("beginPayTime");//付款时间(起)
		String endPayTime = request.getParameter("endPayTime");//付款时间(止)

		InfBfsPayQueryCondition qc = new InfBfsPayQueryCondition();
		if (StringUtils.isNotEmpty(status)) {
			qc.setStatus(status);
		}
		if (StringUtils.isNotEmpty(procInstId)) {
			qc.setProcInstId(procInstId);
		}
		if (StringUtils.isNotEmpty(paylistCode)) {
			qc.setPaylistCode(paylistCode);
		}
		if (StringUtils.isNotEmpty(customerName)) {
			qc.setCustomerName(customerName);
		}
		if (StringUtils.isNotEmpty(projectName)) {
			qc.setProjectName(projectName);
		}
		if (StringUtils.isNotEmpty(provincialCompany)) {
			qc.setProvincialCompany(provincialCompany);
		}
		if (StringUtils.isNotEmpty(beginCreateTime)) {
			qc.setBeginCreateTime(DateUtils.formatStringToDate(beginCreateTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(endCreateTime)) {
			qc.setEndCreateTime(DateUtils.formatStringToDate(endCreateTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(beginPayTime)) {
			qc.setBeginPayTime(DateUtils.formatStringToDate(beginPayTime, "yyyy-MM-dd"));
		}
		if (StringUtils.isNotEmpty(endPayTime)) {
			qc.setEndPayTime(DateUtils.formatStringToDate(endPayTime, "yyyy-MM-dd"));
		}
		List<InfBfsPayVO> list = this.infBfsPayService.searchList(qc);
		for(InfBfsPayVO _vo : list){
			if(StringUtils.isNotEmpty(_vo.getStatus())){
				for(InterfaceConstants.BfsPayStatus _enumstatus : InterfaceConstants.BfsPayStatus.values()){
					if(StringUtils.isNotEmpty(_enumstatus.key()) && (_vo.getStatus()).equals(_enumstatus.key())){
						_vo.setStatusNm(_enumstatus.desc());
						break;
					}
				}
			}
			if(StringUtils.isNotBlank(_vo.getPrjNm())){
				_vo.setProjectName(_vo.getPrjNm());
			}
			if(StringUtils.isNotBlank(_vo.getCstNm())){
				_vo.setCustomerName(_vo.getCstNm());
			}
			if(StringUtils.isNotBlank(_vo.getBuOrgNm())){
				_vo.setOrgNo(_vo.getBuOrgNm());
			}else{
				if(StringUtils.isNotEmpty(_vo.getOrgNo())){
					_vo.setOrgNo(this.infBfsPayService.searchOrgNm(_vo.getOrgNo(), CurrentThreadContext.getCurrentSysCd()));
				}
			}
			if(StringUtils.isNotBlank(_vo.getCstMgrOrgNm())){
				_vo.setProvincialCompany(_vo.getCstMgrOrgNm());
			}else{
				if(StringUtils.isNotEmpty(_vo.getProvincialCompany())){
					_vo.setProvincialCompany(this.infBfsPayService.searchOrgNm(_vo.getProvincialCompany(), CurrentThreadContext.getCurrentSysCd()));
				}
			}
			if(null != _vo.getPayMoneyReal()){
				_vo.setPayMoneyRealdou(DecimalUtils.convertFenToYuan(_vo.getPayMoneyReal()));
			}
			if(null != _vo.getPayMoney()){
				_vo.setPayMoneydou(DecimalUtils.convertFenToYuan(_vo.getPayMoney()));
			}
		}
		ExportParams params = new ExportParams("网银付款记录", "网银付款记录", ExcelType.HSSF);
		//HSSF是POI工程对Excel 97(-2007)文件操作的纯Java实现;
		//XSSF是POI工程对Excel 2007 OOXML (.xlsx)文件操作的纯Java实现
		//SXSSF基于XSSF的低内存占用的API
		params.setColor(HSSFColor.BRIGHT_GREEN.index);//表头颜色
		params.setStyle(ExcelExportStylerDefaultImpl.class);//ExcelExportStylerBorderImpl 有边框样式 ExcelExportStylerColorImpl  有边框间隔行样式 ExcelExportStylerDefaultImpl	默认的样式
		Workbook workbook = ExcelExportUtil.exportExcel(params, InfBfsPayVO.class, list);
		OutputStream ouputStream = null;
		try {
			String filename="网银付款记录";
			filename=new String(filename.getBytes("UTF-8"),"ISO8859-1");
			response.reset();
			response.setCharacterEncoding("utf-8");
			response.setHeader("Content-disposition", "attachment; filename=" + filename + ".xls");// 设定输出文件头
			response.setContentType("application/x-msdownload");// 定义输出类型
			ouputStream = response.getOutputStream();
			workbook.write(ouputStream);
			ouputStream.flush();
			ouputStream.close();
		} catch (UnsupportedEncodingException e) {
			BaseLogUtils.error(logger, "-", "异常", e);
		} catch (IOException e) {
			BaseLogUtils.error(logger, "-", "异常", e);
		}finally {
			//关闭流
			if(ouputStream!=null){
				try {
					ouputStream.close();
				} catch (IOException e) {
			BaseLogUtils.error(logger, "-", "异常", e);
				}
			}
		}

	}
}

